package com.huadao.cart_ccs.data.bo;

import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.main.CartApplication;

public class BaseBO {
    protected byte commondWord;
    protected byte modularType;
    protected byte modularNO;
    protected byte order;
    protected byte error;

    protected byte[] protocol;

    public BaseBO() {
    }

    public BaseBO(byte commondWord, byte modularNO, byte order, byte error) {
        this.commondWord = commondWord;
        this.modularNO = modularNO;
        this.order = order;
        this.error = error;
    }

    public byte getCommondWord() {
        return commondWord;
    }

    public void setCommondWord(byte commondWord) {
        this.commondWord = commondWord;
    }

    public byte getModularNO() {
        return modularNO;
    }

    public void setModularNO(byte modularNO) {
        this.modularNO = modularNO;
    }

    public byte getModularType() {
        return modularType;
    }

    public void setModularType(byte modularType) {
        this.modularType = modularType;
    }

    public byte getOrder() {
        return order;
    }

    public void setOrder(byte order) {
        this.order = order;
    }

    public byte getError() {
        return error;
    }

    public void setError(byte error) {
        this.error = error;
    }

    public byte[] getProtocol() {
        return protocol;
    }

    public void setProtocol(byte[] protocol) {
        this.protocol = protocol;
    }

    //命令字toString
    protected String getCommandWordStr() {
        String commandWordStr = null;
        if (commondWord==CommandWord.readSucc[0]) {
            commandWordStr = CartApplication.getInstance().getString(R.string.readSucc);
        } else if (commondWord==CommandWord.writeSucc[0]) {
            commandWordStr = CartApplication.getInstance().getString(R.string.writeSucc);
        } else if (commondWord==CommandWord.readFail[0]) {
            commandWordStr = CartApplication.getInstance().getString(R.string.readFail);
        } else if (commondWord==CommandWord.writeFail[0]) {
            commandWordStr = CartApplication.getInstance().getString(R.string.writeFail);
        }
        return commandWordStr;
    }

//    protected String getModularType(){
//        String modularTypeStr = null;
//        switch (modularType){
//            case DeviceBO.modularType_CO2:
//                modularTypeStr=CartApplication.getInstance().getString(R.string.mac);
//                break;
//            case PeristalticPumpBO.modularType_CO2:
//                modularTypeStr = CartApplication.getInstance().getString(R.string.peristaltic_pump);
//                break;
//            case MagneticStirrerBO.modularType_CO2:
//                modularTypeStr = CartApplication.getInstance().getString(R.string.magnetic_stirrer);
//                break;
//            case TemperatureBO.modularType_CO2:
//                modularTypeStr = CartApplication.getInstance().getString(R.string.temperature_NO1);
//                break;
//            case O2BO.modularType_CO2:
//                modularTypeStr = CartApplication.getInstance().getString(R.string.O2);
//                break;
//            case CO2BO.modularType_CO2:
//                modularTypeStr = CartApplication.getInstance().getString(R.string.CO2_NO1);
//                break;
//            case ElectronicScaleBO.modularType_CO2:
//                modularTypeStr = CartApplication.getInstance().getString(R.string.electronicScale_NO1);
//                break;
//            case SerialPortBO.modularType_CO2:
//                modularTypeStr = CartApplication.getInstance().getString(R.string.serial_port);
//                break;
//            case VacuumPumpBO.modularType_CO2:
//                modularTypeStr = CartApplication.getInstance().getString(R.string.vacuum_pump);
//                break;
//                default:break;
//        }
//        return modularTypeStr;
//    }

//    protected String getModularStr(){
//        String modularStr = null;
//        switch (modular) {
//            case DeviceBO.deviceMAC:
//                modularStr=CartApplication.getInstance().getString(R.string.mac);
//                break;
//            case PeristalticPumpBO.PeristalticPump_fluidIntake:
//                modularStr = CartApplication.getInstance().getString(R.string.peristaltic_pump_fluidIntake);
//                break;
//            case PeristalticPumpBO.PeristalticPump_circulating:
//                modularStr = CartApplication.getInstance().getString(R.string.peristaltic_pump_circulating);
//                break;
//            case PeristalticPumpBO.PeristalticPump_waste:
//                modularStr = CartApplication.getInstance().getString(R.string.peristaltic_pump_waste);
//                break;
//            case PeristalticPumpBO.PeristalticPump_reclaim:
//                modularStr = CartApplication.getInstance().getString(R.string.peristaltic_pump_reclaim);
//                break;
//            case MagneticStirrerBO.magneticStirrer_NO1:
//                modularStr = CartApplication.getInstance().getString(R.string.magnetic_stirrer);
//                break;
//            case IncubatorBO.CO2_NO1:
//                modularStr = CartApplication.getInstance().getString(R.string.CO2Incubator);
//                break;
//            case ElectronicScaleBO.electronicScale_NO1:
//                modularStr = CartApplication.getInstance().getString(R.string.electronicScale_NO1);
//                break;
//            case MicroscopeBO.microscope:
//                modularStr = CartApplication.getInstance().getString(R.string.microscope);
//                break;
//            case SerialPortBO.liquidLevelMeter:
//                modularStr = CartApplication.getInstance().getString(R.string.liquid_level_meter_door);
//                break;
//            case CultureTankBO.VacuumPump_cultureTank:
//                modularStr = CartApplication.getInstance().getString(R.string.cultureTankElectric);
//                break;
//            case IncubatorBO.VacuumPump_incubator:
//                modularStr = CartApplication.getInstance().getString(R.string.VacuumPump_incubator);
//                break;
//            default:
//                break;
//        }
//        return modularStr;
//    }

    //模块指令-操作指令toString
    protected String getOrderStr(){
        return "";
    }
    //模块指令-模块类型toString
    protected String getModularTypeStr(){
        return "";
    }
    //模块指令-子模块号toString
    protected String getModularNOStr(){
        return String.valueOf(modularNO);
    }

    //指令内容toString
    protected String getOrderContentStr(){
        return "";
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(getCommandWordStr());
        stringBuilder.append(" ");
        stringBuilder.append(getModularTypeStr());
        stringBuilder.append(" ");
        stringBuilder.append(getModularNOStr());
        stringBuilder.append(" ");
        stringBuilder.append(getOrderStr());
        stringBuilder.append(" ");
        if(commondWord==CommandWord.readSucc[0]||commondWord==CommandWord.writeSucc[0]){
            stringBuilder.append(getOrderContentStr());
        }else if(commondWord==CommandWord.readFail[0]||commondWord==CommandWord.writeFail[0]){
            stringBuilder.append("错误码:");
            stringBuilder.append(Integer.toHexString(error & 0xFF).toUpperCase());
        }
        return stringBuilder.toString();
    }
}
